package com.ruoyi.web.controller.ted;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.demooo1.domain.DictDivination;
import com.ruoyi.demooo1.service.IDictDivinationService;
import com.ruoyi.framework.web.service.PermissionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 卦象字典Controller
 *
 * @author ted
 * @date 2023-08-23
 */
@RestController
@RequestMapping("/system/divination")
public class DictDivinationController extends BaseController
{
    @Autowired
    private IDictDivinationService dictDivinationService;

    /**
     * 查询卦象字典列表
     */
    @PreAuthorize("@ss.hasPermi('system:divination:list')")
    @GetMapping("/list")
    public TableDataInfo list(DictDivination dictDivination)
    {
        startPage();
        List<DictDivination> list = dictDivinationService.selectDictDivinationList(dictDivination);
        return getDataTable(list);
    }

    /**
     * 导出卦象字典列表
     */
    @PreAuthorize("@ss.hasPermi('system:divination:export')")
    @Log(title = "卦象字典", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DictDivination dictDivination)
    {
        List<DictDivination> list = dictDivinationService.selectDictDivinationList(dictDivination);
        ExcelUtil<DictDivination> util = new ExcelUtil<DictDivination>(DictDivination.class);
        util.exportExcel(response, list, "卦象字典数据");
    }

    /**
     * 获取卦象字典详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:divination:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(dictDivinationService.selectDictDivinationById(id));
    }
    /**
     * 获取卦象字典详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:divination:query')")
    @GetMapping(value = "/dId"+"/{dId}")
    public AjaxResult getInfoForDid(@PathVariable("dId") String dId)
    {
        return success(dictDivinationService.selectDivinationFprDid(dId));
    }

    /**
     * 新增卦象字典
     */
    @PreAuthorize("@ss.hasPermi('system:divination:add')")
    @Log(title = "卦象字典", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DictDivination dictDivination)
    {
        return toAjax(dictDivinationService.insertDictDivination(dictDivination));
    }

    /**
     * 修改卦象字典
     */
    @PreAuthorize("@ss.hasPermi('system:divination:edit')")
    @Log(title = "卦象字典", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DictDivination dictDivination)
    {
        return toAjax(dictDivinationService.updateDictDivination(dictDivination));
    }

    /**
     * 删除卦象字典
     */
    @PreAuthorize("@ss.hasPermi('system:divination:remove')")
    @Log(title = "卦象字典", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(dictDivinationService.deleteDictDivinationByIds(ids));
    }
}
